
*********************************
** Load correct visits effects:
	estimates use output/causal_visits
		global veffectp = _b[Np]
		global veffecte = _b[Ne]
*********************************



*****************************************
** Load relevant dataset

use "$datapath/intermediate/collect_pdouble.dta", clear
	
	drop if lno==.
	gen id = 1 if raise=="Pe" 
	replace id = 2 if raise=="Pp"
	
*****************************************


*****************************************
** Section 6.0 and footnote 37 - libraries that solve to observed holdings: 
	
	gen similar = (abs(Np-mNp)<.1 ) * (factor==10)
	egen SIMILAR = sum(similar), by(lno)

	tab SIMILAR if factor==10
	
	foreach i in 0 1 {
		foreach f in p e {
			su N`f' if factor==10 & SIMILAR==`i'
			local n`f'`i' = r(mean)
		}
	}
	
	** ratios of holdings for libraries that solve to the truth vs not 
		di `ne1' / `np1'
		di `ne0' / `np0'
		
	keep if SIMILAR==1
	
	
************************
** Section 6.0 & Appendix A - shares of libraries solving to corners


	gen ap = mNp<1 | mNe<1 if raise=="Pp"
	egen AP = max(ap), by(lno)
	tab AP if raise=="Pp" & factor==20

	gen ae = mNp<1 | mNe<1 if raise=="Pe"
	egen AE = max(ae), by(lno)
	tab AE if raise=="Pe" & factor==10

	drop ae ap AE AP

** Tag libraries that solve to corners
	gen tag = mNp<1 | mNe<1
	egen TT = max(tag), by(lno)
	tab TT if raise=="Pe" & factor==10
	

************************


*********************************************	
** Section 6.1 - Delta CS ratios separately for high and low theta: 

preserve 
	drop if TT==1 
	
	gen epref = thetae > thetap

	collapse (mean) CS , by(id factor raise epref)

		gen double x_CS = CS if factor==10
		egen double X_CS = mean(x_CS), by(epref)
		gen r_CS = (CS-X_CS)/X_CS
	
	keep if factor==20

		gen xr_CS = r_CS if raise=="Pe"
		egen Xr_CS = mean(xr_CS), by(epref)
		gen r_CS_ratio = r_CS/Xr_CS if raise=="Pp"
		
		bys epref: su r_CS_ratio
restore 		
	
*********************************************	



*********************************************	
** Appendix - Delta CS ratios only for libraries solving to corners: 

preserve 
	keep if TT==1 
	
	collapse (mean) CS , by(id factor raise)

		gen double x_CS = CS if factor==10
		egen double X_CS = mean(x_CS)
		gen r_CS = (CS-X_CS)/X_CS
	
	keep if factor==20

		gen xr_CS = r_CS if raise=="Pe"
		egen Xr_CS = mean(xr_CS)
		gen r_CS_ratio = r_CS/Xr_CS if raise=="Pp"
		
		bys raise: su r_CS 
		su r_CS_ratio
restore 		
	
*********************************************	




*********************************************	
** Appendix - Delta CS ratios for all libraries: 

preserve 
	
	collapse (mean) CS , by(id factor raise)

		gen double x_CS = CS if factor==10
		egen double X_CS = mean(x_CS)
		gen r_CS = (CS-X_CS)/X_CS
	
	keep if factor==20

		gen xr_CS = r_CS if raise=="Pe"
		egen Xr_CS = mean(xr_CS)
		gen r_CS_ratio = r_CS/Xr_CS if raise=="Pp"

		su r_CS_ratio
restore 		
	
*********************************************	









